# -*- utf-8 -*-
# @Time: 2021/8/2 10:56
# @Author: CACode
from rest_framework import serializers

from .models import Banner, Classify, TabBarImage


class BannerSerializer(serializers.ModelSerializer):
    img = serializers.CharField(max_length=255, help_text="图片的链接")
    title = serializers.CharField(max_length=255, allow_null=True, help_text="图片的描述")
    path = serializers.CharField(max_length=255, allow_null=True, help_text="图片的跳转地址")
    bg_color = serializers.CharField(max_length=50, allow_null=True, default="White", help_text="背景颜色")

    class Meta:
        fields = '__all__'
        model = Banner

    def create(self, validated_data):
        if not validated_data['bg_color']:
            validated_data['bg_color'] = 'white'
        return super(BannerSerializer, self).create(validated_data)


class TabBarImageSerializer(serializers.ModelSerializer):
    class Meta:
        fields = '__all__'
        model = TabBarImage


class ClassifySerializer(serializers.ModelSerializer):
    class Meta:
        fields = '__all__'
        model = Classify


class ClassifyTextSerializer(serializers.ModelSerializer):
    class Meta:
        fields = ['id', 'name']
        model = Classify
